package com.iwhalecloud.bss.kite.cucc.service.route.strategy.impl;

import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.iwhalecloud.bss.kite.cucc.client.api.inf.IInfBcmcServiceBus;
import com.iwhalecloud.bss.kite.cucc.client.dto.inf.InfServContextDTO;
import com.iwhalecloud.bss.kite.cucc.client.dto.pos.KitePosDTO;
import com.iwhalecloud.bss.kite.cucc.service.pos.bcmc.IBcmcPosServiceHandler;
import com.iwhalecloud.bss.kite.cucc.service.route.strategy.IInfServStrategy;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.ztesoft.bss.common.util.SpringUtil;

/**
 * <Description> <br>
 * 调用BCMC服务总线策略
 * 
 * @author XXZ<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2020年12月3日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.route.strategy.impl <br>
 */
public class InfBcmcServiceBusStrategy implements IInfServStrategy {

    /**
     * 外部中心订单归集接口
     * 
     * @return <br>
     */
    @Override
    public Map<String, Object> orderCenterPathVariable(InfServContextDTO context) {
        // 组装下单请求对象
        IBcmcPosServiceHandler ibcmcPosServiceHandler = SpringUtil.getBean(IBcmcPosServiceHandler.class);
        KitePosDTO posDto = ibcmcPosServiceHandler.deal(context);
        String requestParam = JSONObject.toJSON(posDto).toString();

        IInfBcmcServiceBus infServ = SpringUtil.getBean(IInfBcmcServiceBus.class);
        return infServ.orderCenterPathVariable(requestParam);
    }

    /**
     * Description: <br>
     * 获取订单信息
     * 
     * @author XXZ<br>
     * @taskId <br>
     * @param orderId
     * @param flowId
     * @param taskId
     * @return <br>
     */
    @Override
    public Map<String, Object> getWorkOrderInfo(String orderId, String flowId, String taskId) {
        IInfBcmcServiceBus infServ = SpringUtil.getBean(IInfBcmcServiceBus.class);
        return infServ.getWorkOrderInfo(orderId);
    }

    /**
     * 订单更新接口
     * 
     * @param posDto
     * @param custId
     * @param orderId
     * @return
     */
    @Override
    public Map<String, Object> orderCenterUpdatePiece(InfServContextDTO context) {
        IBcmcPosServiceHandler ibcmcPosServiceHandler = SpringUtil.getBean(IBcmcPosServiceHandler.class);
        KitePosDTO posDto = ibcmcPosServiceHandler.deal(context);
        String custId = context.getCustDto().getCustId();
        String orderId = SpringUtil.getBean(IQuerySceneInstService.class).getExtParameterValue(context.getSceneInstId(),
            "orderId");
        
        IInfBcmcServiceBus infServ = SpringUtil.getBean(IInfBcmcServiceBus.class);
        return infServ.orderCenterUpdatePiece(posDto, custId, orderId);
    }

}
